﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _5._25
{
    class Program3
    {
        static void Main(string[] args)
        {
            UDisk u = new UDisk("金士顿");
            MobileHardDisk mhd = new MobileHardDisk("希捷");
            u.Info();
            mhd.Info();

            Computer c = new Computer("联想");
            c.TurnOn();
            c.TurnOff();
            c.Input(u,mhd);
            c.USBs[0]?.Read();
            c.USBs[0]?.Write();
            c.USBs[1]?.Read();
            c.USBs[1]?.Write();
        }
    }

    abstract class MobileStorgeFather
    {
        private string _brand;

        public string Brand { get => _brand; set => _brand = value; }

        protected MobileStorgeFather(string brand)
        {
            this._brand = brand;
        }

        public abstract void Info();
    }

    interface IUSB
    {
        void Read();
        void Write();
    }

    class UDisk : MobileStorgeFather, IUSB
    {
        public UDisk(string brand) : base(brand)
        {
        }

        public override void Info()
        {
            Console.WriteLine($"{this.Brand}U盘");
        }

        public void Read()
        {
            Console.WriteLine($"{this.Brand}u盘正在读取...");
        }

        public void Write()
        {
            Console.WriteLine($"{this.Brand}u盘正在写入...");
        }
    }
    class MobileHardDisk : MobileStorgeFather, IUSB
    {
        public MobileHardDisk(string brand) : base(brand)
        {
        }

        public override void Info()
        {
            Console.WriteLine($"{this.Brand}移动硬盘");
        }

        public void Read()
        {
            Console.WriteLine($"{this.Brand}移动硬盘正在读取...");
        }

        public void Write()
        {
            Console.WriteLine($"{this.Brand}移动硬盘正在写入...");
        }
    }

    class Computer
    {
        private string _brand;

        private IUSB[] _USBs = new IUSB[2];

        public string Brand { get => _brand; set => _brand = value; }
        internal IUSB[] USBs { get => _USBs; set => _USBs = value; }

        public Computer(string brand)
        {
            Brand = brand;
        }

        public void TurnOn()
        {
            Console.WriteLine($"{this.Brand}电脑正在开机");
        }
        public void TurnOff()
        {
            Console.WriteLine($"{this.Brand}电脑正在关机");
        }

        public void Input(params IUSB[] usb)
        {
            if (usb.Length >= 2)
            {
                USBs[0] = usb[0];
                USBs[1] = usb[1];
                Console.WriteLine("插入成功");
            }
            else if (usb.Length == 1)
            {
                USBs[0] = usb[0];
                Console.WriteLine("插入成功");
            }
            else
            {
                Console.WriteLine("请插入");
            }
        }
        public void Output()
        {
            this.USBs[0] = null;
            this.USBs[1] = null;
            Console.WriteLine("拔出成功");
        }
    }
}
